package com.wx.dao.impl;

import com.wx.dao.TransactionDao;
import com.wx.domain.Transaction;
import com.wx.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Date;
import java.util.List;

public class TransactionDaoImpl implements TransactionDao {
    JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public List<Transaction> findByPatientId(String patientId) {
        return jdbcTemplate.query("select * from transaction where patientId =?",
                new BeanPropertyRowMapper<>(Transaction.class),patientId);
    }

    @Override
    public void addTransaction(double money, String patientId) {
        long date = System.currentTimeMillis();
        String id="abc"+date;
        String name="507诊所";
        jdbcTemplate.update("insert into transaction values(?,?,?,?)",id,patientId,name,money);
    }
}
